package com.gsafety.wellsfort.common.context;

import com.gsafety.wellsfort.domain.bo.UserBO;
import com.gsafety.wellsfort.domain.model.organization.Student;
import com.gsafety.wellsfort.domain.model.security.Admin;

/**
 * 登录信息工具类
 *
 * @author tangjiawei
 * @date 2020/04/15
 */
public class LoginContextUtil {
    /**
     * 当前登录用户名
     *
     * @return
     */
    public static String getUserName() {
        LoginContext context = ContextHolder.getContext();
        if (context != null && context.getUserBO() != null) {
            return context.getUserBO().getName();
        }
        return "";
    }

    /**
     * 获取当前用户名
     *
     * @return
     */
    public static String getAccount() {
        LoginContext context = ContextHolder.getContext();
        if (context != null && context.getUserBO() != null) {
            return context.getUserBO().getAccount();
        }
        return "";
    }

    /**
     * 当前登录用户uid
     *
     * @return
     */
    public static Integer getUid() {
        LoginContext context = ContextHolder.getContext();
        if (context != null && context.getUserBO() != null) {
            return context.getUserBO().getUid();
        }
        return null;
    }

    public static UserBO getUserBo() {
        LoginContext context = ContextHolder.getContext();
        if (context != null) {
            return context.getUserBO();
        }
        return null;
    }

    public static Admin getAdmin() {
        LoginContext context = ContextHolder.getContext();
        if (context != null) {
            return context.getAdmin();
        }
        return null;
    }

    public static Student getStudent() {
        LoginContext context = ContextHolder.getContext();
        if (context != null) {
            return context.getStudent();
        }
        return null;
    }

    public static void setContext(LoginContext loginContext) {
        ContextHolder.setContext(loginContext);
    }

    public static void setUserBo(UserBO userBO) {
        LoginContext context = ContextHolder.getContext();
        context.setUserBO(userBO);
    }

    public static void setAdmin(Admin admin) {
        LoginContext context = ContextHolder.getContext();
        context.setAdmin(admin);
    }

    public static void setStudent(Student student) {
        LoginContext context = ContextHolder.getContext();
        context.setStudent(student);
    }
}
